[Apache] Creating rewrite rules for multiple urls in the same folder

Posted by DavidYell on Stack Overflow See other posts from Stack Overflow or by DavidYell
Published on 2010-03-16T10:38:12Z Indexed on 2010/03/16 10:46 UTC
Read the original article Hit count: 209

Filed under:
|

I have been asked by our client to convert a site we created into SEO friendly url format. I've managed to crack a small way into this, but have hit a problem with having the same urls in the same folder.

I am trying to rewrite the following urls,

  1. /review/index.php?cid=intercasino
  2. /review/submit.php?cid=intercasino
  3. /review/index.php?cid=intercasino&page=2#reviews

I would like to get them to,

  1. /review/intercasino
  2. /submit-review/intercasino
  3. /review/intercasino/2#reviews

I've almost got it working using the following rule,

RewriteRule (submit-review)/(.*)$ review/submit.php?cid=$2 [L]
RewriteRule (^review)/(.*) review/index.php?cid=$2

The problem, you may already see, is that /submit-review rewrites to /review, which in turn gets rewritten to index.php, thus my review submission page is lost in place of my index page. I figured that putting [L] would prevent the second rule being called, but it seems that it rewrites both urls in two seperate passes. I've also tried [QSE], and [S=1]

I would rather not have to move my files into different folders to get the rewriting to work, as that just seems too much like bad practise. If anyone could give me some pointers on how to differentiate between these similar urls that would be great!

Thanks (Ref: http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html)

© Stack Overflow or respective owner

Related posts about apache

Related posts about mod-rewrite